package com.edu.medicalpro.ZiDingYiView;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.media.Image;
import android.net.Uri;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.edu.medicalpro.R;

import java.net.URL;

public class ErWeiMaDialog extends Dialog {
    public ErWeiMaDialog(@NonNull Context context) {
        super(context);
    }

    public ErWeiMaDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected ErWeiMaDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }
    public static class Builder{
        private TextView liftText,rightText;
        private ImageView erWeiMa;
        private ErWeiMaDialog erWeiMaDialog;
        private View mLayout;
        private View.OnClickListener liftTextOnClickListener,rightTextOnClickListener;
        public  Builder(Context context){
            erWeiMaDialog = new ErWeiMaDialog(context, R.style.erWeiMaDialog);
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            // 加载布局文件
            mLayout = inflater.inflate(R.layout.er_wei_ma, null, false);
            // 添加布局文件到 Dialog
            erWeiMaDialog.addContentView(mLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

            liftText =  mLayout.findViewById(R.id.lift_text);
            rightText = mLayout.findViewById(R.id.right_text);
            erWeiMa = mLayout.findViewById(R.id.er_wei_ma_img);
        }
        public Builder setImg(Uri uri){
            erWeiMa.setImageURI(uri);
            return this;
        }
        public Builder setLiftText(String text, View.OnClickListener listener) {
            liftText.setText(text);

            liftTextOnClickListener = listener;
            return this;
        }
        public Builder setRightText(String text, View.OnClickListener listener) {
            rightText.setText(text);

            rightTextOnClickListener = listener;
            return this;
        }
        public ErWeiMaDialog create(){
            liftText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int mColor=Color.parseColor("#ff33b5e5");
                    liftText.setTextColor(mColor);
                    rightText.setTextColor(Color.BLACK);
                    liftTextOnClickListener.onClick(view);
                }
            });
            rightText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int mColor=Color.parseColor("#ff33b5e5");
                    rightText.setTextColor(mColor);
                    liftText.setTextColor(Color.BLACK);
                    rightTextOnClickListener.onClick(view);

                }
            });
            //设置布局
            erWeiMaDialog.setContentView(mLayout);
            //设置是否可取消
            erWeiMaDialog.setCancelable(true);
            //点击空白关闭
            erWeiMaDialog.setCanceledOnTouchOutside(true);
            return erWeiMaDialog;
        }
    }
}
